package com.mdd.front.controller;

import com.mdd.common.core.PageResult;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.collect.IGoodsCollectService;
import com.mdd.front.validate.collect.GoodsCollectPageParam;
import com.mdd.front.validate.collect.GoodsCollectParam;
import com.mdd.front.vo.collect.GoodsCollectListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 服务收藏管理
 */
@Api(tags = "收藏管理")
@RestController
@RequestMapping("api/collect")
public class GoodsCollectController {

    @Resource
    IGoodsCollectService iGoodsCollectService;

    /**
     * 服务收藏列表
     *
     * @param params 搜索参数
     * @return Object
     */
    @ApiOperation(value = "收藏管理 - 列表")
    @GetMapping("/list")
    public PageResult<GoodsCollectListVo> list(GoodsCollectPageParam params) {
        Long userId = Long.valueOf(LikeFrontThreadLocal.getUserId());
        params.setUserId(userId);
        return iGoodsCollectService.list(params);
    }

    /**
     * 服务收藏新增
     *
     * @param goodsCollectParam 参数
     * @return Object
     */
    @ApiOperation(value = "收藏管理 - 收藏")
    @PostMapping("/add")
    public void add(@Validated(value = GoodsCollectParam.create.class) @RequestBody GoodsCollectParam goodsCollectParam) {
        Long userId = Long.valueOf(LikeFrontThreadLocal.getUserId());
        goodsCollectParam.setUserId(userId);
        iGoodsCollectService.add(goodsCollectParam);
    }


    /**
     * 服务收藏删除
     *
     * @param id 参数
     * @return Object
     */
    @Deprecated
    @GetMapping("/del")
    public void del(@RequestParam Long id) {
        iGoodsCollectService.del(id);
    }

}
